﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IllustratedCsharp7_chapt21_3_ww
{
    class Chapt21_3AsyncMethodEx1_ReturnTask_T
    {
        static void _Main()
        {
            Task<int> value = DoAsyncStuff.CalculateSumAsync(5, 6);
            //处理其他事情

            Console.WriteLine("Value:{0}", value.Result);
        }
        
    }
    static class DoAsyncStuff
    {
        //使用返回Task<int>对象的异步方法
        public static async Task<int> CalculateSumAsync(int i1, int i2)
        {
            int sum = await Task.Run(() => GetSum(i1, i2));
            return sum;
        }
        private static int GetSum(int i1, int i2) { return i1 + i2; }
    }
}
